home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
The World of Computer Software.iso
/
drcpas10.zip
/
ROOTDIR.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-11-17
|
5KB
|
171 lines
{$A+,B-,D-,E-,F-,I+,L-,N-,O-,R-,S+,V-}
{$M 16384,0,655360}
program rootdir;
(* another absio.pas example: display the root directory of the current
disk without (much) help from DOS; also compute locations of FAT's,
root dir and data from information in boot sector.
*)
uses dos, absio, tools;
(*
Note: DOS directories have the following structure:
Filename = 8 bytes
Extention = 3 bytes
Attribute = 1 byte
Unused = 10 bytes
Time = 2 bytes
Date = 2 bytes
Cluster = 2 bytes
File Size = 4 bytes
*)
type
dirent =
record
filename : array[1..8] of char;
extention : array[1..3] of char;
attribute : byte;
unused : array[1..10] of byte;
time : word;
date : word;
cluster : word;
size : longint;
end;
sector = array[0..511] of byte;
dirsect = array[1..16] of dirent;
procedure abort (message : string);
begin
writeln ('Error: ', message);
halt (2);
end;
function getdisk : byte;
var
reg : registers;
begin
reg.ah := $19;
intr ($21, reg);
getdisk := reg.al;
end;
procedure printent (e : dirent);
begin
if e.filename[1] = #$e5 then
begin
e.filename[1] := '.';
write (e.filename, '.', e.extention, e.cluster:8);
writeln (' (deleted)');
end
else
if (e.attribute AND VolumeID) = VolumeID then
writeln (chr(65+getdisk), ': "', e.filename, e.extention, '":')
else
begin
write (e.filename, '.', e.extention, e.cluster:8);
if (e.attribute AND Directory) = Directory then
write (' DIR') else write (' ');
if (e.attribute AND Sysfile) = Sysfile then
write (' SYS') else write (' ');
if (e.attribute AND Hidden) = Hidden then
write (' HID') else write (' ');
if (e.attribute AND Archive) = Archive then
write (' ARC') else write (' ');
if (e.attribute AND ReadOnly) = ReadOnly then
write (' RO') else write (' ');
writeln;
end;
end;
var
bootsec : sector;
s : dirsect;
bps, skip, ent, spf, spt, tpc, hid, ot : word;
spc, fats, media, id, sig : byte;
nt, tot : longint;
(*
Offset Format and example Contents
0 jmp around either a 3-byte jmp or 2-byte jmp plus NOP.
3 db 'MSDOS5.0' OEM name
B dw 512 bytes/sector
D db 4 sectors/cluster
E dw 1 reserved sectors at front of disk
10 db 2 number of copies of the FAT
11 dw 512 number of root directory entries
13 dw 0 *old* total number of sectors
15 db 0F8h media descriptor
16 dw 64 sectors/FAT
18 dw 32 sectors/track
1A dw 64 tracks/cylinder
1C dd 32 "hidden" sectors
20 dd 65504 *new* total number of sectors
24 db 080h physical disk ID
25 db 0 reserved (used as scratch during boot)
26 db 029h extended boot record signature
27 db 1ch,9eh,0adh,16h volume serial
2B db ' ' volume *label* if this is a diskette
36 db 'FAT16 ' ASCII text describing type of FAT
*)
var
fat, d : byte;
dat, sect : word;
begin
absread (getdisk, 0, 1, bootsec);
if abserror <> 0 then
begin
writeln ('Error ',hexw(abserror),' reading boot sector.');
halt (1);
end;
bps := word((@bootsec[$b])^);
spc := byte((@bootsec[$d])^);
skip := word((@bootsec[$e])^);
fats := byte((@bootsec[$10])^);
ent := word((@bootsec[$11])^);
ot := word((@bootsec[$13])^);
media := byte((@bootsec[$15])^);
spf := word((@bootsec[$16])^);
spt := word((@bootsec[$18])^);
tpc := word((@bootsec[$1a])^);
hid := word((@bootsec[$1c])^);
nt := longint((@bootsec[$20])^);
writeln ('Information for drive ', chr(65+getdisk), ':');
writeln ('Bytes per Sector: ':30, bps:5);
writeln ('Sectors per Cluster: ':30, spc:5);
writeln ('Reserved Sectors: ':30, skip:5);
writeln ('File Allocation Tables: ':30, fats:5);
writeln ('Root Directory Entries: ':30, ent:5);
writeln ('Sectors per FAT: ':30, spf:5);
tot := ot + nt;
writeln ('Total Number of Sectors: ':30, tot:5);
writeln;
writeln ('Boot Sector: ':20, 0:4);
for fat := 1 to fats do
writeln ('FAT ':17, fat, ': ', skip+(fat-1)*spf:2, ' - ', skip+fat*spf-1);
dat := skip+fats*spf+ent*32 DIV bps;
writeln ('Root Directory: ':20, skip+fats*spf:2, ' - ', dat-1);
writeln ('Data: ':20, skip+fats*spf+ent*32 DIV bps:2, ' - ', ((tot-(dat-1)) DIV spc)*spc+dat-1);
writeln;
for sect := skip+fats*spf to dat-1 do
begin
absread (getdisk, sect, 1, s);
if abserror <> 0 then
begin
writeln ('Error ',hexw(abserror),' reading sector ',sect,'.');
halt (1);
end;
for d := 1 to bps DIV 32 do
if (s[d].filename[1] <> #0) then
printent(s[d]);
end;
end.